#!/usr/bin/env python
# coding=utf-8
from flask import Blueprint

from plant.base.beanret import BeanRet
from plant.base.tools.config import Config
from plant.service.airquality import GroveAirQualitySensor

pitop = Blueprint('air', __name__)


@pitop.route('/air/read')
def read():
    '''
    read air quality
    :return:
    '''
    pin = int(Config().read("air_quality", "pin"))
    sensor = GroveAirQualitySensor(int(pin))
    value = sensor.value
    print(value)
    if value > 100:
        info = "High Pollution"
    else:
        info = "Air Quality OK"

    return BeanRet(success=True, data={'value': value, 'info': info}).toJson()
